#include "pm/tag.h"

using namespace pm;

const wxString Tag::TABLE_NAME = wxT("tags");

Tag::Tag(wxSQLite3ResultSet& res)
: db::Table(res)
, name(res, wxT("name"))
, colour(res, wxT("colour"))
{
}

db::update_value_t Tag::prepare_insert(wxSQLite3Database& db)
{
	wxSQLite3Statement stmt = db.PrepareStatement("insert into tags values(null, ?, ?)");
	stmt.Bind(1, name());
	stmt.Bind(2, colour().GetAsString(wxC2S_HTML_SYNTAX));
	return db::update_value_t(true, stmt);
}

db::update_value_t Tag::prepare_update(wxSQLite3Database& db)
{
	wxSQLite3Statement stmt = db.PrepareStatement("update tags set name = ?, colour = ? where id = ?");
	stmt.Bind(1, name());
	stmt.Bind(2, colour().GetAsString(wxC2S_HTML_SYNTAX));
	stmt.Bind(3, id());
	return db::update_value_t(true, stmt);
}
